//rust语言的注释和c/c++是相同的。
/* 这是个测试程序，力图体现rust语言的基本特点*/
		
use std::io;
const PADSIZE:i32 = 19;
static MYNAME:&'static str="gerry xiao";

fn main(){
    let i:i32=5; //i32是带符号32位整型变量,还有i8,i16,i32,i64,无符号变量为u32
    let ii=5; //你也可以使用类型推断
    //i=10;你不可以更改i的值，变量默认是不变的。
    let mut iii=6; //你必须这样声明变量，mut表示可改变。
    iii=10; //这样就可以了。
    print_sum(i,ii);
       
    println!("Guess the number!");
    println!("Please input your guess.");
    let mut guess = String::new();
    io::stdin().read_line(&mut guess)
        .expect("Failed to read line");
    println!("you guessed: {}",guess);
    let f: fn(i32)->i32;
    fn plus_one(i:i32)->i32 {i+1};
    f=plus_one;
    println!("plus_one is {}.",f(3));
    loop {
        println!("loop forever!");
        break;
    }
    test_ownership();

    let mut point_list: Vec<Point>  =Vec::new();

    let one_step=Point {x:0,y:0,color: Color::WHITE,seq:1,dead_at:0};
     println!("the neighors is {:?}",one_step.neighbors());
    point_list.push(one_step);
    println!("the is now is {:?}",point_list);
    let mut point_block_list: Vec<Vec<Point>> =Vec::new();
    point_block_list.push(point_list);
    println!("the block is {:?}",point_block_list);    
    let closure1=|me|me+i;
    closure1(30);
    
}

fn print_sum(x:i32,y:i32) {
    println!("sum is: {}",x+y);
}
//let f: fn(i32)->i32;

fn test_ownership() {
    let v=vec![1,2,3];
    let v2=&v;
    println!("v[0] is: {}",v[0]);
}

#[derive(Debug)]
struct Point {
    x: i32,
    y: i32,
    color: Color,
    seq: i32,
    dead_at: i32,
}
impl Point {
    fn neighbors(&self)->[(i32,i32);4] {
        [(self.x,self.y+1),(self.x+1,self.y),(self.x - 1,self.y),(self.x,self.y-1)]
    }
}
        
#[derive(Debug)]
enum Color {
    WHITE,
    BLACK
}

enum Action {
    Pass,
    PlayAt {x: i32,y: i32},
    TimeOut,
    Resign
}


    
